package com.middlegroup.common.enums;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

/**
 *所有配置一定要放置在这里统一
 * @author pc
 * @date 2019/1/24
 */
public enum ConfigKeyEnums {
    SUBJECT_PAYPLATFORM_RSA_PUB_KEY("subject","pay_platform_rsa_pub_key","支付中台公钥"),
    SUBJECT_RSA_PRI_KEY("subject","subject_rsa_pri_key","对应主体的私钥"),
    SUBJECT_CODE("subject","subjectCode","对应主体编码"),
    SUBJECT_RSA_PUB_KEY("subject","subject_rsa_pub_key","对应主体的公钥"),
    SUBJECT_PAYPLATFORM_GATEWAY_URL("subject","pay_platform_notify_url","中台网关地址"),
    PAY_PLATFORM_RSA_PRI_KEY("pay_platform","rsa_pri_key","中台私钥"),
    PAY_PLATFORM_RSA_PUB_KEY("pay_platform","rsa_pub_key","中台私钥"),


    MERCHANTNO("merchantNo","商户标识"),
    REQUESTURL("requestUrl","请求url"),
    PRIVATEKEY("privateKey","私钥"),
    PUBLICKEY("publicKey","公钥"),
    DESKEY("desKey","签名密钥"),
    CALLBACKURL("callBackUrl","回调地址"),
    MD5KEY("MD5Key","MD5Key"),

    //微信支付相关配置
    appid("appid","服务商的APPID"),
    mch_id("mch_id","商户号"),
    mch_key("mch_key","商户key"),
    refund_mch_key("refund_mch_key","退款回调解密商户key"),
    notify_url("notify_url","支付回调地址"),
    wap_url("wap_url","WAP网站URL地址"),
    url("url","微信支付统一下单接口url"),
    orderquery_url("orderquery_url","微信支付订单查询url"),
    refund_url("refund_url","微信支付退款接口url"),
    refund_orderquery_url("refund_orderquery_url","微信支付退款查询接口url"),
    refund_notify_url("refund_notify_url","微信支付退款接口url"),

    //Paypal支付相关配置
    mode("mode","沙箱或者正式"),
    clientId("clientId","账户clientId"),
    clientSecret("clientSecret","账户clientSecret"),
    ipPort("ipPort","Paypal回调支付确认"),
    validateUrl("validateUrl","paypal回调验证"),
    //支付宝支付相关配置
    ALIAPPID("ALIAPPID","阿里的APPID"),
    ALIRSA_PRIVATE_KEY("ALIRSA_PRIVATE_KEY","阿里的私钥pkcs8格式的"),
    ALINOTIFY_URL("ALINOTIFY_URL","服务器异步通知页面路径"),// 服务器异步通知页面路径 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    ALIRETURN_URL("ALIRETURN_URL","页面跳转同步通知页面路径"), // 页面跳转同步通知页面路径 需http://或者https://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问 商户可以自定义同步跳转地址
    ALICHARSET("ALICHARSET","阿里的编码"),
    ALIFORMAT("ALIFORMAT","阿里的返回格式"),
    ALIPAY_PUBLIC_KEY("ALIPAY_PUBLIC_KEY","支付宝公钥自己生成的"),
    SIGNTYPE("SIGNTYPE","阿里的加密格式"),
    ALIURL("ALIURL","请求网关"),
    TIMEOUT_EXPRESS("TIMEOUT_EXPRESS","订单失效时间"),
    ALIPAY_PUBLIC_KEY_ALI("ALIPAY_PUBLIC_KEY_ALI","ALI公钥阿里的")


    ;

    private String category;
    private String name;
    private String remark;

    /**
     * @param category
     * @param name
     */
    ConfigKeyEnums(String category, String name, String remark) {
        this.category = category;
        this.name = name;
        this.remark = remark;
    }

    ConfigKeyEnums(String name, String remark) {
        this.name = name;
        this.remark = remark;
    }

    /**
     * 根据code获取name
     * @param category
     * @return
     */
    public static String getName(String category) {
        for (ConfigKeyEnums e : ConfigKeyEnums.values()) {
            if (StringUtils.equals(e.getCategory(),category)) {
                return e.name;
            }
        }
        return null;
    }

    /**
     *将该枚举全部转化成json
     * @return
     */
    public static String toJson(){
        JSONArray jsonArray = new JSONArray();
        for (ConfigKeyEnums e : ConfigKeyEnums.values()) {
            JSONObject object = new JSONObject();
            object.put("category", e.getCategory());
            object.put("name", e.getName());
            object.put("remark",e.getRemark());
            jsonArray.add(object);
        }
        return jsonArray.toString();
    }

    /**
     * 重写toString，单个转化成json
     * @return
     */
    @Override
    public String toString() {
        JSONObject object = new JSONObject();
        object.put("category",category);
        object.put("name",name);
        object.put("remark",remark);
        return object.toString();
    }

    public String getCategory() {
        return category;
    }

    public String getRemark() {
        return remark;
    }

    public void  setRemark(String remark){
        this.remark = remark;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
